package com.recruitment.auth.mq;

import com.recruitment.common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 用户消息生产者
 */
@Slf4j
@Component
public class UserMessageProducer {
    
    @Autowired
    private RabbitTemplate rabbitTemplate;
    
    /**
     * 用户注册成功消息
     */
    public static final String USER_REGISTER_QUEUE = "user.register.queue";
    public static final String USER_REGISTER_EXCHANGE = "user.register.exchange";
    public static final String USER_REGISTER_ROUTING_KEY = "user.register";
    
    /**
     * 发送用户注册成功消息
     * @param userId 用户ID
     */
    public void sendUserRegisterMessage(Long userId) {
        try {
            String message = "用户注册成功，用户ID: " + userId;
            rabbitTemplate.convertAndSend(USER_REGISTER_EXCHANGE, USER_REGISTER_ROUTING_KEY, message);
            log.info("发送用户注册消息成功: {}", message);
        } catch (Exception e) {
            log.error("发送用户注册消息失败: {}", e.getMessage(), e);
        }
    }
    
    /**
     * 用户登录消息
     */
    public static final String USER_LOGIN_QUEUE = "user.login.queue";
    public static final String USER_LOGIN_EXCHANGE = "user.login.exchange";
    public static final String USER_LOGIN_ROUTING_KEY = "user.login";
    
    /**
     * 发送用户登录消息
     * @param userId 用户ID
     */
    public void sendUserLoginMessage(Long userId) {
        try {
            String message = "用户登录，用户ID: " + userId;
            rabbitTemplate.convertAndSend(USER_LOGIN_EXCHANGE, USER_LOGIN_ROUTING_KEY, message);
            log.info("发送用户登录消息成功: {}", message);
        } catch (Exception e) {
            log.error("发送用户登录消息失败: {}", e.getMessage(), e);
        }
    }
} 